import { Component } from "react";

class Alert extends Component {
    constructor(props) {
        super(props);
    }
    timer = null;
    state = { counts: 0 };
    componentWillUnmount() {
        console.log("组件即将卸载");
        clearInterval(this.timer);
    }
    componentDidMount() {
        this.timer = setInterval(() => {
            this.setState({ counts: this.state.counts + 1 });
            console.log("update");
        }, 1000);
        console.log("组件已经挂载");
    }
    render() {
        return (
            <div className='alert alert-danger'>
                当前数值为：{this.state.counts}
            </div>
        );
    }
}

export default Alert;
